home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / (gcc-1.37.π) / driver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-01  |  20.7 KB  |  837 lines  |  [TEXT/KAHL]

  1. /*
  2.     driver program for mpw native gcc compiler
  3.     
  4.   Copyright (C) 1990, 1992 Apple Computer, Inc.
  5.     
  6.     Written by:
  7.         Larry Rosenstein
  8.         Brent H. Pease
  9.     
  10.     
  11.     Accepts most MPW C command line arguments and transforms them into gcc arguments.
  12.     Issues warnings for MPW C command arguments that are NOT supported
  13.     Accepts certain GCC C command arguments that do not conflict with MPW C
  14. */
  15.  
  16. #include <types.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #define MAXFILENAME 255
  22.  
  23. int    run_cpp = 1;
  24. int run_cc1 = 1;
  25. int run_asm = 1;
  26. int optimize = 1;
  27. int quiet_flag = 1;
  28. int echo_cmds = 0;
  29. int make_short = 0;
  30. int got_mc68020 = 0;
  31. int debug_gcc = 0;
  32.  
  33. char* output_filename;
  34. char* input_filename;
  35. char* tool_place;
  36. char* tmp;
  37.  
  38. char *cpp_options;
  39. char *cc1_options;
  40. char *asm_options;
  41.  
  42. char *tool_suffix = "";
  43.  
  44. char tmp_filename[MAXFILENAME];
  45. char cpp_filename[MAXFILENAME];
  46. char asm_filename[MAXFILENAME];
  47. char out_filename[MAXFILENAME];
  48. char *shorten_filename = "•••asm_warnings•••";
  49. char *shorten_out_filename = "•••asm_modified•••";
  50.  
  51. /*Handle the sym options notypes, nolines, novars*/
  52. int HandleSymOpts(char *pOpt) {
  53.     register char *ptr = pOpt;
  54.     
  55.     while(1) {
  56.         /*Check for notypes*/
  57.         if (strncmp(ptr, "notypes", 7) == 0) {
  58.             warn_not_implemented("notypes");
  59.             ptr += 7;
  60.         
  61.         /*Check for nolines*/
  62.         } else if (strncmp(ptr, "nolines", 7) == 0) {
  63.             warn_not_implemented("nolines");
  64.             ptr += 7;
  65.         
  66.         /*Check for novars*/
  67.         } else if (strncmp(ptr, "novars", 6) == 0) {
  68.             warn_not_implemented("novars");
  69.             ptr += 6;
  70.         
  71.         /*Check for must not be a sym option*/
  72.         } else {
  73.             return 0;
  74.         }
  75.         if ((*ptr != ',') || (*ptr == 0)) {
  76.             return 1;
  77.         }
  78.         ptr++;
  79.     }
  80. }
  81.  
  82. /*Handle the -opt*/
  83. void HandleOptOpts(char *pOpt) {
  84.     register char *ptr = pOpt;
  85.     
  86.     while(1) {
  87.         /*Check for off(mpwc)*/
  88.         if (strncmp(ptr, "off", 3) == 0) {
  89.             optimize = 0;
  90.             ptr += 3;
  91.         
  92.         /*Check for on(mpwc)*/
  93.         } else if (strncmp(ptr, "on", 2) == 0) {
  94.             optimize = 1;
  95.             ptr += 2;
  96.         
  97.         /*Check for full(mpwc)*/
  98.         } else if (strncmp(ptr, "full", 4) == 0) {
  99.             optimize = 1;
  100.             make_short = 1;
  101.             ptr += 4;
  102.         
  103.         /*Check for nopeep(mpwc)*/
  104.         } else if (strncmp(ptr, "nopeep", 6) == 0) {
  105.             strcat(cc1_options, " -fno-peephole");
  106.             ptr += 6;
  107.         
  108.         /*Check for nocse(mpwc)*/
  109.         } else if (strncmp(ptr, "nocse", 5) == 0) {
  110.             warn_not_implemented("nocse");
  111.             ptr += 5;
  112.         
  113.         /*Check for high(custom)*/
  114.         } else if (strncmp(ptr, "high", 4) == 0) {
  115.             optimize = 2;
  116.             make_short = 1;
  117.             ptr += 4;
  118.         
  119.         /*Check for branch(custom)*/
  120.         } else if (strncmp(ptr, "branch", 6) == 0) {
  121.             make_short = 1;
  122.             ptr += 6;
  123.         
  124.         /*Unknown option*/
  125.         } else {
  126.             fprintf (stderr, "Warning: unknown option for -opt.\n");
  127.         }
  128.         if ((*ptr != ',') || (*ptr == 0)) {
  129.             return;
  130.         }
  131.         ptr++;
  132.     }
  133. }
  134.  
  135. main (argc, argv)
  136. int argc;
  137. char* argv[];
  138. {
  139.     int i, badopt;
  140.     char* arg;
  141.     char* missing;
  142.     char* basename;
  143.     
  144.     cpp_options = (char *)malloc(10000);
  145.     cc1_options = (char *)malloc(10000);
  146.     asm_options = (char *)malloc(10000);
  147.     *cpp_options = 0;
  148.     *cc1_options = 0;
  149.     *asm_options = 0;
  150.     
  151.     output_filename = "";
  152.     input_filename = "";
  153.     tool_place = "";
  154.     tmp = ":";
  155.     
  156.     strcpy(cpp_options, "-D__GNUC__=1");
  157.     cc1_options[0] = '\0';
  158.     //strcpy(asm_options, "-w");
  159.     
  160.     for (i=1; i<argc; i++) {
  161.         arg = argv[i];
  162.         badopt = 0;
  163.         missing = "";
  164.         
  165.         if (arg[0] == '-') {
  166.             switch(arg[1]) {
  167.                 case 'a':
  168.                     /*Check for -ansi(gcc)*/
  169.                     if (strcmp(arg, "-ansi") == 0) {
  170.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  171.                         
  172.                     /*Check for -asm(custom)*/
  173.                     } else if (strcmp(arg, "-asm") == 0) {
  174.                         run_asm = 0;
  175.                     
  176.                     /*Unknown option*/
  177.                     } else {
  178.                         badopt = 1;
  179.                     }
  180.                     break;
  181.                     
  182.                 case 'b':
  183.                     /*Check for -b(mpwc)*/
  184.                     if (arg[2] == '\0') {
  185.                         /*Transform into gcc command*/
  186.                         strcat(cc1_options, " -mb");
  187.                         
  188.                     /*Check for -b2 and -b3(mpwc)*/
  189.                     } else if ( (arg[2] == '2' || arg[2] == '3') && arg[3] == '\0' ) {
  190.                         /*Not supported*/
  191.                         fprintf (stderr, "Warning: %s ignored, substituting -b.\n", arg);
  192.                         strcat(cc1_options, " -mb");
  193.                     
  194.                     } else if (strcmp(arg, "-bigseg") == 0) {
  195.                         warn_not_implemented(arg);
  196.                     
  197.                     /*Unknown option*/
  198.                     } else {
  199.                         badopt = 1;
  200.                     }
  201.                     break;
  202.                     
  203.                 case 'c':
  204.                     /*Check for -c(mpwc)*/
  205.                     if (arg[2] == '\0') {
  206.                         run_cc1 = 0;
  207.                     
  208.                     /*Unknown option*/
  209.                     } else {
  210.                         badopt = 1;
  211.                     }
  212.                     break;
  213.                     
  214.                 case 'd':
  215.                     /*Check for -d string(mpwc)*/
  216.                     if (arg[2] == '\0') {
  217.                         if (++i<argc) {
  218.                             /*transform into gcc command*/
  219.                             strcat(cpp_options, " -D");  strcat(cpp_options, argv[i]);
  220.                         } else {
  221.                             missing = "symbol";
  222.                         }
  223.                                         
  224.                     } else {
  225.                         /* Probably a debugging option -d<x> - pass thru to cc1 */
  226.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  227.                     }
  228.                     break;
  229.                     
  230.                 case 'e':
  231.                     /*Check for -e(mpwc)*/
  232.                     if (arg[2] == '\0') {
  233.                         /*Transform into gcc argument*/
  234.                         strcat(cpp_options, " -C");
  235.                         run_cc1 = 0;
  236.                     
  237.                     /*Check for -e2(mpwc)*/
  238.                     } else if (arg[2] == '2' && arg[3] == '\0') {
  239.                         run_cc1 = 0;
  240.                     
  241.                     /*Check for -elems881(mpwc)*/
  242.                     } else if (strcmp(arg, "-elems881") == 0) {
  243.                         strcat(cc1_options, " -melems881");
  244.                     
  245.                     /*Unknown option*/
  246.                     } else {
  247.                         badopt = 1;
  248.                     }
  249.                     break;
  250.                     
  251.                 case 'f':
  252.                     /*Check for fx(undocumented)*/
  253.                     if (arg[2] == 'x' && arg[3] == '\0') {
  254.                         /*Make sure there is another option*/
  255.                         if (++i>=argc) {
  256.                             missing = "number";
  257.                         
  258.                         /*Check for 30*/
  259.                         } else if (strcmp(argv[i], "30") == 0) {
  260.                             strcat(cc1_options, " -mfx30");
  261.                         
  262.                         /*Unknown fx argument*/
  263.                         } else {
  264.                             fprintf (stderr, "Warning: -fx %s ignored.\n", argv[i]);
  265.                         }
  266.                     
  267.                     /*Check for a whole slew of gcc options*/
  268.                     } else if (arg[2] != '\0') {
  269.                         /* pass it on to cc1 and let it complain */
  270.                         strcat(cc1_options, " ");
  271.                         strcat(cc1_options, arg);
  272.                     
  273.                     /*Unknown option*/
  274.                     } else {
  275.                         badopt = 1;
  276.                     }
  277.                     break;
  278.                 
  279.                 case 'i':
  280.                     /*check for -i pathname(mpwc)*/
  281.                     if (arg[2] == '\0') {
  282.                         /*Make sure there are more arguments*/
  283.                         if (++i<argc) {
  284.                             /*Transform into gcc argument*/
  285.                             strcat(cpp_options, " '-I");
  286.                             strcat(cpp_options, argv[i]);
  287.                             strcat(cpp_options, "'");
  288.                         } else {
  289.                             missing = "directory";
  290.                         }
  291.                     } else {
  292.                         badopt = 1;
  293.                     }
  294.                     break;
  295.                 
  296.                 case 'k':
  297.                     /* check for -k (MPW C) */
  298.                     if (arg[2] == '/0')
  299.                     {
  300.                         warn_not_implemented(arg);
  301.                         if (argv[i+1] != '-')    /* directory name to go along with -k */
  302.                             i++;
  303.                     }
  304.                             
  305.                     /* check for -kon (equiv to -opt branch) */
  306.                     else if (strcmp(arg, "-kon") == 0)
  307.                         make_short = 1;
  308.                     else
  309.                         badopt = 1;
  310.                         break;
  311.                 
  312.                 case 'm':
  313.                     /*Check for -m(mpwc)*/
  314.                     if (arg[2] == '\0') {
  315.                         /*Translate into gcc lingo*/
  316.                         strcat(cc1_options, " -mm");
  317.                         if (got_mc68020 == 0) {
  318.                             /*Make sure the user knows whats up*/
  319.                             fprintf (stderr, "Warning: -m forces -mc68020\n");
  320.                             strcat(cpp_options, " -Dmc68020");
  321.                             strcat(cc1_options, " -m68020");
  322.                             got_mc68020 = 1;
  323.                         }
  324.                     
  325.                     /*Check for makedep(custom)*/
  326.                     } else if (strcmp(arg, "-makedep") == 0) {
  327.                         /*Translate*/
  328.                         strcat(cpp_options, " -M");
  329.                         run_cc1 = 0;
  330.                     
  331.                     /*Check for -mbg(mpwc)*/
  332.                     } else if (strcmp(arg, "-mbg") == 0) {
  333.                         /*Make sure there is another argument*/
  334.                         if (++i<argc) {
  335.                             
  336.                             /*Check for off*/
  337.                             if (strcmp(argv[i], "off") == 0) {
  338.                                 strcat(cc1_options, " -mbgoff -fomit-frame-pointer");
  339.                             
  340.                             /*Check for full*/
  341.                             } else if (strcmp(argv[i], "full") == 0) {
  342.                                 /*Default*/
  343.                                 
  344.                             /*Check for on*/
  345.                             } else if (strcmp(argv[i], "on") == 0) {
  346.                                 fprintf (stderr, "Warning: -mbg on is not supported, try -mbg full.\n");
  347.                             
  348.                             /*Unknown option*/
  349.                             } else {
  350.                                 missing = "on|full";
  351.                             }
  352.                         } else {
  353.                             missing = "on|full";
  354.                         }
  355.                     
  356.                     /*Check for -mc68020(mpwc)*/
  357.                     } else if (strcmp(arg, "-mc68020") == 0) {
  358.                         /*Add in options if needed*/
  359.                         if (got_mc68020 == 0) {
  360.                             strcat(cpp_options, " -Dmc68020");
  361.                             strcat(cc1_options, " -m68020");
  362.                             got_mc68020 = 1;
  363.                         }
  364.                     
  365.                     /*Check for -mc68881(mpwc)*/
  366.                     } else if (strcmp(arg, "-mc68881") == 0) {
  367.                         strcat(cpp_options, " -Dmc68881");
  368.                         strcat(cc1_options, " -m68881");
  369.                     
  370.                     /*Check for -mnoseg(custom)*/
  371.                     } else if (strcmp(arg, "-mnoseg") == 0) {
  372.                         strcat(cc1_options, " -mnoseg");
  373.                     
  374.                     /*Check for -model(mpwc)*/
  375.                     } else if (strcmp(arg, "-model") == 0) {
  376.                         if (++i < argc) {
  377.                             
  378.                             /*Check for near*/
  379.                             if (strcmp(arg, "near") == 0) {
  380.                                 warn_not_implemented("-model near");
  381.                             
  382.                             /*Check for far*/
  383.                             } else if (strcmp(arg, "far") == 0) {
  384.                                 warn_not_implemented("-model far");
  385.                             
  386.                             /*Check for nearData*/
  387.                             } else if (strcmp(arg, "nearData") == 0) {
  388.                                 warn_not_implemented("-model nearData");
  389.                             
  390.                             /*Check for farData*/
  391.                             } else if (strcmp(arg, "farData") == 0) {
  392.                                 warn_not_implemented("-model farData");
  393.                             
  394.                             /*Check for nearCode*/
  395.                             } else if (strcmp(arg, "nearCode") == 0) {
  396.                                 warn_not_implemented("-model nearCode");
  397.                             
  398.                             /*Check for farCode*/
  399.                             } else if (strcmp(arg, "farCode") == 0) {
  400.                                 warn_not_implemented("-model farCode");
  401.                             
  402.                             /*Unknown options*/
  403.                             } else {
  404.                                 missing = "near|far|nearData|farData|nearCode|farCode";
  405.                             }
  406.                             
  407.                         /*Unknown option*/
  408.                         } else {
  409.                             missing = "near|far|nearData|farData|nearCode|farCode";
  410.                         }
  411.                     /*Unknown option*/
  412.                     } else {
  413.                         badopt = 1;
  414.                     }
  415.                     break;
  416.                     
  417.                 case 'n':
  418.                     if (!strcmp(arg, "-noext")) {
  419.                         tool_suffix = "";
  420.  
  421.                     } else if (!strcmp(arg, "-nocpp")) {
  422.                         run_cpp = 0;
  423.  
  424.                     /*Check for -n(mpwc)*/
  425.                     } else if (arg[2] == '\0') {
  426.                       warn_not_implemented(arg);
  427.                     
  428.                     /*Unknown option*/
  429.                     } else {
  430.                         badopt = 1;
  431.                     }
  432.                     break;
  433.                     
  434.                 case 'o':
  435.                     /*Check for -opt(mpwc)*/
  436.                     if (strcmp(arg, "-opt") == 0) {
  437.                         /*Make sure we have enough arguments left*/
  438.                         if (++i<argc) {
  439.                             HandleOptOpts(argv[i]);
  440.                         
  441.                         /*Not enough arguments*/
  442.                         } else {
  443.                             missing = "on|off|full";
  444.                         }
  445.                     
  446.                     /*Check for -o objname(mpwc)*/
  447.                     } else if (arg[2] == '\0') {
  448.                         /*Make sure we have enough arguments*/
  449.                         if (++i<argc) {
  450.                             output_filename = argv[i];
  451.                         
  452.                         /*Not enough arguments*/
  453.                         } else {
  454.                             missing = "output filename";
  455.                         }
  456.                     
  457.                     /*Unknown option*/
  458.                     } else {
  459.                         badopt = 1;
  460.                     }
  461.                     break;
  462.     
  463.                 case 'p':
  464.                     /*Check for -p(mpwc)*/
  465.                     if (arg[2] == '\0') {
  466.                         /*Translate into gcc args*/
  467.                         strcat(cpp_options, " -v");
  468.                         strcat(cc1_options, " -version");
  469.                         quiet_flag = 0;
  470.                         strcat(asm_options, " -p");
  471.                         echo_cmds = 1;
  472.                     
  473.                     /*Check for -pedantic(gcc)*/
  474.                     } else if (strcmp(arg, "-pedantic") == 0) {
  475.                         strcat(cpp_options, " -pedantic");
  476.                         strcat(cc1_options, " -pedantic");
  477.                     
  478.                     /*Unkown option*/
  479.                     } else {
  480.                         badopt = 1;
  481.                     }
  482.                     break;
  483.                     
  484.                 case 'r':
  485.                     /*Check for -r(mpwc)*/
  486.                     if (arg[2] == '\0') {
  487.                         strcat(cc1_options, " -Wimplicit");
  488.                     
  489.                     /*Unkown*/
  490.                     } else {
  491.                         badopt = 1;
  492.                     }
  493.                     break;
  494.                     
  495.                 case 's':
  496.                     /*check for -s segment(mpwc)*/
  497.                     if (arg[2] == '\0') {
  498.                         /*Make sure we have enough options*/
  499.                         if (++i<argc) {
  500.                             strcat(cc1_options, " -s '");
  501.                             strcat(cc1_options, argv[i]);
  502.                             strcat(cc1_options, "'");
  503.                         } else {
  504.                             missing = "segment name";
  505.                         }
  506.                     }
  507.                     
  508.                     /*Check for -sym(mpwc)*/
  509.                     else if (strcmp(arg, "-sym") == 0) {
  510.                         /*Make sure we have enough args*/
  511.                         if (++i<argc) {
  512.                             if ((strcmp(argv[i], "full") == 0) || (strcmp(argv[i], "on") == 0)) {
  513.                                 if (HandleSymOpts(argv[i+1])) {
  514.                                     i++;
  515.                                 }
  516.                                 strcat(asm_options, " -sym ");  strcat(asm_options, argv[i]);
  517.                                 fprintf (stderr, "Warning: symbolic info will be produced by assembler.\n");
  518.                             } else if (strcmp(argv[i], "off") == 0) {
  519.                                 /*default*/
  520.                             } else {
  521.                                 missing = "on|off|full";
  522.                             }
  523.                         } else {
  524.                             missing = "option";
  525.                         }
  526.                     
  527.                     /*Unknown option*/
  528.                     } else {
  529.                         badopt = 1;
  530.                     }
  531.                     break;
  532.                     
  533.                 case 't':
  534.                     /*Check for -t(mpwc)*/
  535.                     if (arg[2] == '\0') {
  536.                         quiet_flag = 0;
  537.                         strcat(asm_options, " -t");
  538.                     
  539.                     /*Check for -traditional(gcc)*/
  540.                     } else if (strcmp(arg, "-traditional") == 0) {
  541.                         strcat(cpp_options, " -traditional");
  542.                         strcat(cc1_options, " -traditional");
  543.                         
  544.                     /*Check for tools(custom)*/
  545.                     } else if (strcmp(arg, "-tools") == 0) {
  546.                         /*Make sure there are enough args*/
  547.                         if (++i<argc) {
  548.                             tool_place = argv[i];
  549.                         } else {
  550.                             missing = "directory";
  551.                         }
  552.                     
  553.                     /*Check for -trace(mpwc)*/
  554.                     } else if (strcmp(arg, "-trace") == 0) {
  555.                         /*Make sure there are enough args*/
  556.                         if (++i<argc) {
  557.                             /*Check for on*/
  558.                             if (strcmp(argv[i], "on") == 0) {
  559.                                 strcat(cc1_options, " -trace on");
  560.                             
  561.                             /*Check for off*/
  562.                             } else if (strcmp(argv[i], "off") == 0) {
  563.                                 strcat(cc1_options, " -trace off");
  564.                             
  565.                             /*Check for always*/
  566.                             } else if (strcmp(argv[i], "always") == 0) {
  567.                                 strcat(cc1_options, " -trace always");
  568.                             
  569.                             /*Check for never*/
  570.                             } else if (strcmp(argv[i], "never") == 0) {
  571.                                 strcat(cc1_options, " -trace never");
  572.                             
  573.                             /*Unknown option*/
  574.                             } else {
  575.                                 missing = "on|off|always|never";
  576.                             }
  577.                         
  578.                         /*Unknown option*/
  579.                         } else {
  580.                             missing = "on|off|always|never";
  581.                         }
  582.                     
  583.                     /*Unknown option*/
  584.                     } else {
  585.                         badopt = 1;
  586.                     }
  587.                     break;
  588.                 
  589.                 case 'u':
  590.                     /*check for -u(mpwc)*/
  591.                     if (arg[2] == '\0') {
  592.                         /*Make sure there are enough args*/
  593.                         if (++i<argc) {
  594.                             /*Translate into gcc*/
  595.                             strcat(cpp_options, " -U");  strcat(cpp_options, argv[i]);
  596.                         
  597.                         /*Not enough args*/
  598.                         } else {
  599.                             missing = "symbol";
  600.                         }
  601.                         
  602.                     /*Unknown option*/
  603.                     } else {
  604.                         badopt = 1;
  605.                     }
  606.                     break;
  607.                     
  608.                 case 'w':
  609.                     /*Check for -w(mpwc)*/
  610.                     if (arg[2] == '\0') {
  611.                         strcat(cc1_options, " -w");
  612.                     
  613.                     /*Check for -w2(mpwc)*/
  614.                     } else if (arg[2] == '2' && arg[3] == '\0') {
  615.                         strcat(cc1_options, " -Wall");
  616.                     
  617.                     /*Check for -warnings(mpwc)*/
  618.                     } else if (strcmp(arg, "-warnings") == 0) {
  619.                         /*Make sure there are enough args*/
  620.                         if (++i<argc) {
  621.                             
  622.                             /*Check for on*/
  623.                             if (strcmp(argv[i], "on") == 0) {
  624.                                 strcat(cc1_options, " -Wall");
  625.                             
  626.                             /*Check for full*/
  627.                             } else if (strcmp(argv[i], "full") == 0) {
  628.                                 strcat(cc1_options, " -Wall");
  629.                             
  630.                             /*Check for off*/
  631.                             } else if (strcmp(argv[i], "off") == 0) {
  632.                                 strcat(cc1_options, " -w");
  633.                             
  634.                             /*Unknown option*/
  635.                             } else {
  636.                                 missing = "on|off|full";
  637.                             }
  638.  
  639.                         /*Unknown option*/
  640.                         } else {
  641.                             missing = "on|off|full";
  642.                         }
  643.                     
  644.                     /*Unknown option*/
  645.                     } else {
  646.                         badopt = 1;
  647.                     }
  648.                     break;
  649.                 
  650.                 case 'W':
  651.                     /*Check for -W(gcc)*/
  652.                     if (arg[2] == '\0') {
  653.                         strcat(cc1_options, " -W");
  654.                     
  655.                     /*Check for -Wall(gcc)*/
  656.                     } else if (strcmp(arg, "-Wall") == 0) {
  657.                         strcat(cc1_options, " -Wall");
  658.                     
  659.                     /*Check for a slew of gcc options*/
  660.                     } else if (arg[2] != '\0') {
  661.                         /* pass it to cc1 and let it complain */
  662.                         strcat(cc1_options, " ");  strcat(cc1_options, arg);
  663.                     } else {
  664.                         badopt = 1;
  665.                     }
  666.                     break;
  667.                     
  668.                 case 'y':
  669.                     /*Check for -y(mpwc)*/
  670.                     if (arg[2] == '\0') {
  671.                         if (++i<argc) {
  672.                             tmp = arg;
  673.                         } else {
  674.                             missing = "directory";
  675.                         }
  676.                     } else {
  677.                         badopt = 1;
  678.                     }
  679.                     break;
  680.     
  681.                 default:
  682.                     badopt = 1;
  683.             }
  684.             
  685.             if (missing[0] != '\0') {
  686.                 fprintf (stderr, "Warning: missing %s after \"%s\".\n", missing, arg);
  687.             } else if (badopt) {
  688.                 fprintf (stderr, "Warning: invalid option %s ignored.\n", arg);
  689.             }
  690.         
  691.         /*Check for filename*/
  692.         } else if (input_filename[0] == '\0') {
  693.             input_filename = arg;
  694.         
  695.         /*Extra file names is a no no*/
  696.         } else {
  697.             fprintf (stderr, "Warning: extra input filename %s ignored.\n", arg);
  698.         }
  699.     }
  700.     
  701.     /*Not enough filenames is a no no*/
  702.     if (input_filename[0] == '\0') {
  703.         fprintf (stderr, "Error: no input filename.\n");
  704.         exit(2);
  705.     }
  706.     
  707.     strcpy(tmp_filename, tmp);
  708.     if ( (basename = strrchr(input_filename, ':')) != NULL)
  709.         ++basename;
  710.     else
  711.       basename = input_filename;
  712.     strcat(tmp_filename, basename);
  713.     
  714.     if (run_cc1) {
  715.         strcpy(cpp_filename, tmp_filename);
  716.         strcat(cpp_filename, ".cpp");
  717.     }
  718.     
  719.     strcpy(asm_filename, tmp_filename);
  720.     strcat(asm_filename, ".a");
  721.     
  722.     if (output_filename[0] == '\0') {
  723.         strcpy(out_filename, input_filename);
  724.         strcat(out_filename, ".o");
  725.         output_filename = out_filename;
  726.     }
  727.     else if (output_filename[strlen(output_filename)-1] == ':') { // it's a directory, copy basename so we get .c.o 
  728.         strcpy(out_filename, output_filename);                                          // not .c.a.o
  729.         strcat(out_filename, basename);                                                            
  730.         strcat(out_filename, ".o");
  731.         output_filename = out_filename;
  732.     }
  733.         
  734.     if (quiet_flag)
  735.         strcat(cc1_options, " -quiet");
  736.         
  737.     if (optimize)
  738.         strcat(cc1_options, " -O");
  739.     else if (optimize >= 2)
  740.         strcat(cc1_options, " -O2");
  741.         
  742.     printf ("set oldexit {exit}\n");
  743.     printf ("set exit 0\n");
  744.             
  745.     if (run_cpp) {
  746.         if (echo_cmds)
  747.             printf ("\techo \"'%s'cpp%s '%s' %s '%s'\"\n", tool_place, tool_suffix, input_filename, cpp_options, cpp_filename);
  748.         printf (           "'%s'cpp%s '%s' %s '%s'\n",   tool_place, tool_suffix, input_filename, cpp_options, cpp_filename);
  749.         printf ("if {status} == 0\n");
  750.     }
  751.         
  752.     if (run_cc1) {
  753.         if (echo_cmds)
  754.             printf ("\techo \"'%s'cc1%s %s '%s' -o '%s' -dumpbase '%s'\"\n", tool_place, tool_suffix, cc1_options, cpp_filename, asm_filename, tmp_filename);
  755.         printf (         "\t'%s'cc1%s %s '%s' -o '%s' -dumpbase '%s'\n",   tool_place, tool_suffix, cc1_options, cpp_filename, asm_filename, tmp_filename);
  756.         printf ("\tif {status} == 0\n");
  757.         if (!debug_gcc && run_cpp) {
  758.             printf ("\t\tdelete -i -y '%s'\n", cpp_filename);
  759.         }
  760.         
  761.         if (run_asm) {
  762.             if (make_short) {
  763.                 if (echo_cmds)
  764.                     printf ("\t\techo \"asm %s '%s' -o '%s' ∑ '%s'\"\n", asm_options, asm_filename, output_filename, shorten_filename);
  765.                 printf ("\t\techo -n > '%s'\n", shorten_filename);
  766.                 printf (         "\t\tasm %s '%s' -o '%s' ∑ '%s'\n",   asm_options, asm_filename, output_filename, shorten_filename);
  767.                 printf ("\t\tloop\n");
  768.                 if (echo_cmds)
  769.                   printf ("\t\t\techo \"Search -sf /•### Warning 210/ '%s' >> dev:null\"\n", shorten_filename);
  770.                 printf (         "\t\t\tSearch -sf /•### Warning 210/ '%s' >> dev:null\n",   shorten_filename);
  771.                 printf ("\t\t\tif {status} == 0\n");
  772.                 if (echo_cmds)
  773.                     printf ("\t\t\t\techo \"'%s'shorten -a '%s' -e '%s' -o '%s'\"\n", tool_place, asm_filename, shorten_filename, shorten_out_filename);
  774.                 printf (         "\t\t\t\t'%s'shorten -a '%s' -e '%s' -o '%s'\n",   tool_place, asm_filename, shorten_filename, shorten_out_filename);
  775.                 if (echo_cmds)
  776.                   printf ("\t\t\t\techo \"move -y '%s' '%s'\"\n", shorten_out_filename, asm_filename);
  777.                 printf (         "\t\t\t\tmove -y '%s' '%s'\n",   shorten_out_filename, asm_filename);
  778.                 if (echo_cmds)
  779.                     printf ("\t\t\t\techo \"asm %s '%s' -o '%s' ∑ '%s'\"\n", asm_options, asm_filename, output_filename, shorten_filename);
  780.                 printf (         "\t\t\t\tasm %s '%s' -o '%s' ∑ '%s'\n",   asm_options, asm_filename, output_filename, shorten_filename);
  781.                 printf ("\t\t\telse\n");
  782.                 if (!debug_gcc)
  783.                 {
  784.                     printf ("\t\t\t\tdelete -i -y '%s'\n", shorten_filename);
  785.                     printf ("\t\t\t\tdelete -i -y '%s'\n", shorten_out_filename);
  786.                 }
  787.                 printf ("\t\t\t\tbreak\n");
  788.                 printf ("\t\t\tend\n");
  789.                 printf ("\t\tend\n");
  790.             }
  791.             else
  792.             {
  793.                 if (echo_cmds)
  794.                     printf ("\t\techo \"asm -w %s '%s' -o '%s'\"\n", asm_options, asm_filename, output_filename);
  795.                 printf (         "\t\tasm -w %s '%s' -o '%s'\n",   asm_options, asm_filename, output_filename);
  796.             }
  797.             printf ("\t\tif {status} == 0\n");
  798.             if (!debug_gcc)
  799.                 printf ("\t\t\tdelete -i -y '%s'\n", asm_filename);
  800.             printf ("\t\telse\n");
  801.             printf ("\t\t\tset exit {oldexit}\n");
  802.             printf ("\t\t\texit 2\n");
  803.             printf ("\t\tend\n");
  804.         }
  805.         printf ("\telse\n");
  806.         if (!debug_gcc) {
  807.             if (run_cpp)
  808.                 printf ("\t\tdelete -i -y '%s'\n", cpp_filename);
  809.             printf ("\t\tdelete -i -y '%s'\n", asm_filename);
  810.         }
  811.         printf ("\t\tset exit {oldexit}\n");
  812.         printf ("\t\texit 2\n");
  813.         printf ("\tend\n");
  814.         
  815.     }
  816.     printf ("else\n");
  817.     if (!debug_gcc) {
  818.         printf ("\tdelete -i -y '%s'\n", cpp_filename);
  819.     }
  820.     printf ("\tset exit {oldexit}\n");
  821.     printf ("\texit 2\n");
  822.     printf ("end\n");
  823.     
  824. /*    if (echo_cmds)*/
  825. /*        printf ("set echo {oldecho}\n");*/
  826.     printf ("set exit {oldexit}\n");
  827.     
  828.     exit(0);
  829. }
  830.  
  831. warn_not_implemented(arg)
  832. char *arg;
  833. {
  834.   fprintf (stderr, "Warning: %s ignored, not implemented yet.\n", arg);
  835. }
  836.  
  837.